package com.clss.emergencycall.utils;

import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.view.View;
import android.view.ViewGroup;

public class ViewUtils {
    private static final String TAG = "ViewUtils";

    /**
     * 获取中心坐标位置
     */
    public static int[] getCenterLocation(View view) {
        final int[] location = new int[2];
        view.getLocationOnScreen(location);
        return location;
    }

    public static int[] getGroupLocation(ViewGroup group) {
        final int[] location = new int[2];
        group.getLocationOnScreen(location);
        return location;
    }

    public static int getViewWidth(View view) {
        ViewGroup.LayoutParams params = view.getLayoutParams();
        return params.width;
    }

    public static int getViewHeight(View view) {
        ViewGroup.LayoutParams params = view.getLayoutParams();
        Lg.i(TAG, "getViewWidth: " + params.height);
        return params.height;
    }

    public static int[] getViewMeasure(View view) {
        int[] ints = new int[2];
        int width = View.MeasureSpec.makeMeasureSpec(0,
                View.MeasureSpec.UNSPECIFIED);
        int height = View.MeasureSpec.makeMeasureSpec(0,
                View.MeasureSpec.UNSPECIFIED);
        view.measure(width, height);
        ints[0] = view.getMeasuredWidth(); // 获取宽度
        ints[1] = view.getMeasuredHeight();

        return ints;
    }

    /**
     * 添加xuan旋转动画
     */
    public static void getAnimRotate(int time, View view) {
        ObjectAnimator ra = ObjectAnimator.ofFloat(view,"rotation", 0f, 360f);
        ra.setDuration(time);
        ra.setRepeatCount(ValueAnimator.INFINITE);
        ra.setRepeatMode(ValueAnimator.RESTART);
        ra.start();
    }
}
